<%--
  Created by IntelliJ IDEA.
  User: sunhao
  Date: 2016/4/13
  Time: 16:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>应发工资</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <%--<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">--%>
  <link href="/static/bui/css/bs3/dpl.css" rel="stylesheet" type="text/css"/>
  <link href="/static/bui/css/bs3/bui.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div class="doc-content">
  <div class="panel">
    <div class="panel-header">
      <h3>工资列表</h3>
    </div>

    <div class="row">
      <div class="span21 offset3 control-row-auto">
        <div id="grid"></div>
        <input type="hidden" name="lesson">
      </div>
    </div>

    <script type="text/javascript" src="/static/bui/js/jquery-1.8.1.min.js"></script>
    <script type="text/javascript" src="/static/bui/js/bui.js"></script>
    <script type="text/javascript" src="/static/bui/js/config.js"></script>
    <script type="text/javascript">

      BUI.use(['bui/grid', 'bui/data', 'bui/form'], function (Grid, Data, Form) {
        var columns = [
                  {title: '教师姓名', dataIndex: 'teacher', width: '15%'},
                  {title: '工资信息', dataIndex: 'info', width: '40%'},
                  {title: '金额', dataIndex: 'pay', width: '10%'}
                ],
        //默认的数据
                data = [
                  <c:forEach items="${salary}" var="r">
                  {
                    _id: '${r._id}',
                    teacher: '${r.teacher}',
                    info: '${r.info}',
                    pay: '${r.pay}'
                  },
                  </c:forEach>
                ],
                store = new Data.Store({
                  data: data,
                  pageSize: 10
                }),
                grid = new Grid.Grid({
                  render: '#grid',
                  columns: columns,
                  width: '100%',
//                    forceFit: true,
                  plugins: [Grid.Plugins.AutoFit],
                  store: store,
                  bbar: {
                    pagingBar: true,
                    elCls: 'image-pbar'
                  },
                  plugins: [Grid.Plugins.CheckSelection],
                  tbar: {
                    items: [
                      {
                        btnCls: 'button button-small',
                        text: '<i class="icon-align-center"></i>确认发放',
                        listeners: {
                          'click': delFunction
                        }
                      }]
                  }
                });
        grid.render();


        function delFunction() {
          var selections = grid.getSelection();
          delItems(selections);
        }

        function delItems(items) {
          var _ids = [];
          BUI.each(items, function (item) {
            _ids.push(item._id)
          });
          if (_ids.length) {
            BUI.Message.Confirm('请确认发放信息是否正确？', function () {
              $.ajax({
                type: 'POST',
                url: '/salary/faSalary?_ids=' + _ids,
                success: function (msg) {
                  if (msg == 'success') {
                    msg = "确认成功！";
                    BUI.Message.Alert(msg, function () {
                      window.location.href = '/salary/listyingfa.do';
                    }, 'success')
                  } else {
                    msg = '确认失败,'
                    BUI.Message.Alert(msg, function () {
                      window.location.href = '/jsp/error/noAuthority.jsp';
                    }, 'error')
                  }
                }
              })
            })
          }
        };
        var form = new Form.HForm({
          srcNode: '#J_Form'
        });
      });
    </script>
  </div>
</div>
</div>
</body>
</html>
